package com.rich.web.servlet;

import java.util.List;

import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.rich.domain.Product;
import com.rich.service.ProductServer;
import com.rich.service.impl.ProductServerImpl;
import com.rich.utils.BeanFactory;

/**
 * 在加载首页时候先获取最新商品和热门商品
 * Servlet implementation class IndexServlet
 */
@WebServlet("/index")
public class IndexServlet extends BaseServlet {
	private static final long serialVersionUID = 1L;

	@Override
	public String index(HttpServletRequest request, HttpServletResponse response) {
		try {
			//调用productServer查询最新商品和热门商品
			ProductServer ps = (ProductServer) BeanFactory.getBean("ProductService");
			List<Product> hostList = ps.findHot();
			List<Product> newList = ps.findNew(); 
			//将两个list放到request域中
			request.setAttribute("hostList", hostList);
			request.setAttribute("newList", newList);
		} catch (Exception e) {
		}
		return "/jsp/index.jsp";
	}
}